home *** CD-ROM | disk | FTP | other *** search
/ PC World Interactive 1 / PC World Interactive 1 - Nisan 1997.iso / nostalji / bbs / music / sbbook.arj / SBBOOK / SOURCE / TC / PLAYMIDI.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-27  |  3.2 KB  |  118 lines

  1. /*********************************************************************
  2. *
  3. *  PROGRAM NAME: PLAYMIDI.C
  4. *
  5. *  COMPILER:     Borland/Turbo C/C++
  6. *
  7. *  DESCRIPTION: Plays a .MID MIDI file from the disk using the SBMIDI
  8. *               driver (accessed from SBSIM).  To run the program,
  9. *               type the following at the command line:
  10. *
  11. *               PLAYMIDI FILENAME
  12. *
  13. *               Where FILENAME is the drive/path/filename of the .MID
  14. *               file to play.
  15. *
  16. *  NOTE: SBSIM driver must be loaded before running this program.
  17. *
  18. *********************************************************************/
  19. #define  MIDI_DRIVER  0x10
  20.  
  21. #include <fcntl.h>
  22. #include <ctype.h>
  23. #include <conio.h>
  24. #include <io.h>
  25. #include <stdio.h>
  26. #include "drvrfunc.c"
  27. #include "drvrfunc.h"
  28.  
  29.  
  30. /********************************************************************/
  31. void main(int argc, char **argv)
  32. {
  33.   char Command,
  34.        UserQuit;
  35.  
  36.   int    FileHandle;
  37.   SIMERR RetValue;
  38.  
  39.   if (argc != 2)  // argc = no. of parameters entered on command line
  40.   {
  41.     puts("Command line must contain EXACTLY ONE filename parameter!");
  42.     return;  // Terminate program
  43.   }
  44.  
  45.  
  46.   /*--- SEE IF SBSIM DRIVER HAS LOADED --*/
  47.   SIMint = FindDvr("SBSIM", 0x0103);  // Get SBSIM's interrupt no.
  48.   if (SIMint == 0)
  49.   {
  50.     puts("SBSIM driver not loaded!");
  51.     return;  // Terminate program
  52.   }
  53.  
  54.   /*--- SEE IF MIDI DRIVER HAS LOADED ---*/
  55.   if (!(GetDrvrs() & MIDI_DRIVER))
  56.   {
  57.     puts("SBMIDI not loaded!");
  58.     return;  // Terminate program
  59.   }
  60.  
  61.  
  62.   /*--- LOAD THE FILE -------------------*/
  63.   if ((FileHandle = _open(argv[1], O_BINARY | O_RDONLY)) == -1)
  64.   {
  65.     printf("FILE: %s not successfully opened!\n", argv[1]);
  66.     return;  // Terminate program
  67.   }
  68.  
  69.  
  70.   /*--- StartSnd() LOADS THE FILE AND INITIALIZES THE SBMIDI DRIVER ---*/
  71.   RetValue = StartSnd(Midi, (void far *) argv[1], NULL, NULL);
  72.   if (RetValue != SIMerr_NoErr)
  73.   {
  74.     printf("ERROR CALLING SBSIM: %s\n", errorMsg[RetValue]);
  75.     _close(FileHandle);
  76.     return;  // Terminate program
  77.   }
  78.  
  79.   /*--- PlaySnd() BEGINS PLAYING THE FILE -------------*/
  80.   RetValue = PlaySnd(Midi);
  81.   if (RetValue != SIMerr_NoErr)
  82.   {
  83.     printf("ERROR CALLING SBSIM: %s\n", errorMsg[RetValue]);
  84.     _close(FileHandle);
  85.     return;  // Terminate program
  86.   }
  87.  
  88.   clrscr();  // Clear screen
  89.   printf("\n\n\n\n\n     SELECT ONE OF THE FOLLOWING OR WAIT UNTIL DONE:\n\n");
  90.   printf("                   (P)ause\n");
  91.   printf("                   (R)esume\n");
  92.   printf("                   (Q)uit\n");
  93.  
  94.   UserQuit = FALSE;
  95.  
  96.   /*--- PROCESS USER INTERACTION OR WAIT FOR SOUND TO STOP -----------*/
  97.   do
  98.   {
  99.     if (kbhit())  // Was a key pressed?
  100.     {
  101.       Command = toupper(getch());  // Get char that's in buffer
  102.       if (Command == 'P')
  103.     PauseSnd(Midi);
  104.       else if (Command == 'R')
  105.     ResumeSnd(Midi);
  106.       else if (Command == 'Q')
  107.     UserQuit = TRUE;
  108.     }
  109.     // Exit do-while loop if file is done playing or user typed 'Q'
  110.   } while (GetSndStat(Midi) != 0 && UserQuit == FALSE);
  111.  
  112.  
  113.   /*--- IF SOUND IS STILL PLAYING AND USER HIT 'Q', STOP THE SOUND ---*/
  114.   if (GetSndStat(Midi) != 0 && UserQuit == TRUE)
  115.     StopSnd(Midi);
  116.  
  117.   return;
  118. }